package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.constant.Result;
import com.itheima.service.MemberService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @PackageName: com.itheima.controller
 * @ClassName: ReportMember
 * @Author: super
 * @Date: 2020/10/15 11:02
 * @Description:
 */
@RestController
@RequestMapping("/memberReport")
public class ReportMemberController {

    /**
     * 远程注入service
     */
    @Reference
    private MemberService memberService;

    /**
     * 查询区间内的会员数量变化
     * @param
     * @return
     */
    @RequestMapping("/findMemberNumberByDate")
    public Result findMemberNumberByDate(@RequestBody String[] strings) {
        try {
            // 拼接成 2002-01-31样式
            String endDate = strings[1] + "-31";
            // 调用接口方法
            Map memberMap = memberService.findMemberNumberByDate(strings[0],endDate);
            // 返回查询成功的结果,提示语句,响应数据
            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS, memberMap);
        } catch (Exception e) {
            e.printStackTrace();
            // 返回错误结果,提示语句
            return new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }
    }
}
